package lagouHomeWork;

import java.io.*;

/**
 * @author StarryHorizon
 * @create 2022-01-04 15:13
 */
public class homeWork2 {

    public static void main(String[] args) {
        BufferedReader br = null;
        PrintStream ps = null;

        try {
            //1.把数据写入到缓冲区
            br = new BufferedReader(new InputStreamReader(System.in));
            ps = new PrintStream(new FileOutputStream("abc.txt"));

            //2.提示用户输入内容并使用变量记录
            while (true) {
                System.out.println("请输入内容");
                String s = br.readLine();
                //3.判断用户输入的内容是否为"end",若是则循环结束
                if ("end".equals(s)) {
                    System.out.println("程序结束");
                    break;
                }
                //4.若不是则将用户输入的内容写到文件/abc.txt中
                ps.println(s);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            //5.关闭流对象
            if (null != ps) {
                ps.close();
            }
            if (null != br) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
